const mysql = require('mysql2/promise');

async function main() {
    const db = {
        host: process.env.DB_HOST || '43.143.253.188',
        port: parseInt(process.env.DB_PORT || '3306', 10),
        user: process.env.DB_USER || 'nextjs',
        password: process.env.DB_PASS || 'yEAiRE2jcxTyRBy5',
        database: process.env.DB_NAME || 'nextjs',
    };
    let conn;
    try {
        conn = await mysql.createConnection(db);
        const [cols] = await conn.execute(
            'SELECT COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA = ? AND TABLE_NAME = ? ORDER BY ORDINAL_POSITION',
            [db.database, 'level_experience']
        );
        console.log('Columns:', cols.map(c => c.COLUMN_NAME).join(', '));

        const [cnt] = await conn.execute(
            'SELECT COUNT(*) AS total, SUM(standard_exp_per_fight IS NOT NULL) AS filled FROM level_experience'
        );
        console.log('Rows:', cnt[0]);

        const samples = [15, 22, 30, 40, 41, 50, 60, 70, 90, 120];
        for (const lvl of samples) {
            const [rows] = await conn.execute('SELECT level, experience, standard_exp_per_fight FROM level_experience WHERE level = ?', [lvl]);
            console.log('Sample', rows[0] || { level: lvl, missing: true });
        }
    } catch (e) {
        console.error('Inspect error:', e && e.message ? e.message : e);
        process.exit(1);
    } finally {
        if (conn) await conn.end();
    }
}

main().catch(e => { console.error(e); process.exit(1); });
